package com.flyzing.genl.service;

import java.io.File;
import java.util.Date;
import java.util.List;

import com.flyzing.genl.dto.BaseMapperParamsFile;
import com.flyzing.genl.po.ColumnPO;
import com.flyzing.genl.po.TablePO;
import com.flyzing.genl.util.GenConfigHelper;
import com.flyzing.genl.util.TemplateHelper;

/**
 * @author yaoguangyao
 * @Date 2020年12月31日
 */
public class GenBaseMapperParamsFile implements IGenFile {
	private static final int ROWS = 1000; //limit rows

	@Override
	public void generate(TablePO table, List<ColumnPO> columns) {
		String packagesMapper = GenConfigHelper.getProperty("package.mapper");
		String path = JAVA_ROOT_PATH + "/" + packagesMapper.replaceAll("\\.", "/") + "/BaseMapperParams.java";

		BaseMapperParamsFile baseParamsFile = new BaseMapperParamsFile();
		baseParamsFile.setPack(packagesMapper);
		baseParamsFile.setAuthor(AUTHOR);
		baseParamsFile.setCreateDate(DATE_FORMAT.format(new Date()));
		String rowsStr = GenConfigHelper.getProperty("BaseMapperParams.rows", String.valueOf(ROWS));
		baseParamsFile.setRows(rowsStr);
		
		File file = new File(path);
		file.getParentFile().mkdirs();
		TemplateHelper.getInstance().process("BaseMapperParams", path, baseParamsFile);
	}

}
